package cn.zhpdmmz.hotel.controller;

import cn.zhpdmmz.entity.Reservation;
import cn.zhpdmmz.service.IReservationService;
import cn.zhpdmmz.vo.CheckInVo;
import cn.zhpdmmz.vo.ReservationVo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Map;

/**
 * (Reservation)表控制层
 *
 * @author CJW
 * @since 2022-04-23 01:28:14
 */
@RestController
@RequestMapping("reservation")
public class ReservationController {
    /**
     * 服务对象
     */
    @Autowired
    private IReservationService reservationService;

    /**
     * 分页查询
     *
     * @param reservation 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public ResponseEntity<List<Reservation>> queryAll(Reservation reservation) {
        return ResponseEntity.ok(this.reservationService.queryAll(reservation));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Reservation> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.reservationService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param reservation 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Reservation> add(@RequestBody Reservation reservation) {
        return ResponseEntity.ok(this.reservationService.insert(reservation));
    }

    /**
     * 编辑数据
     *
     * @param reservation 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Reservation> edit(@RequestBody Reservation reservation) {
        return ResponseEntity.ok(this.reservationService.update(reservation));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.reservationService.deleteById(id));
    }

    @GetMapping("/page")
    public PageInfo page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, Reservation reservation) {
        PageHelper.startPage(pageNum,pageSize);
        List<Reservation> list = this.reservationService.queryAll(reservation);
        PageInfo<List> pageInfo = new PageInfo(list);
        return pageInfo;
    }
    /**
     * 添加客户
     * 步骤1
     * @return 新增结果
     */
    @GetMapping("/addCustomer")
    public ResponseEntity<Map<String, Object>> addCustomer(ReservationVo reservationVo) {
        return ResponseEntity.ok(this.reservationService.addCustomer(reservationVo));
    }
    /**
     * 取消添加客户
     * 步骤1—1
     * @return 新增结果
     */
    @PostMapping("/cancelAddCustomer")
    public ResponseEntity <Boolean> cancelAddCustomer() {
        return ResponseEntity.ok(this.reservationService.cancelAddCustomer());
    }

    /**
     * 步骤二 办理入住
     *
     * @param reservationVo
     * @return
     */
    @GetMapping("/checkInByReservation")
    public ResponseEntity <Boolean> checkInByReservation(ReservationVo reservationVo) {
        return ResponseEntity.ok(this.reservationService.checkInByReservation(reservationVo));
    }
}
